﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using DTO;
using Business;

namespace Airplane
{
    public partial class DatVe : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                XuLyTimChuyenBay tcb = new XuLyTimChuyenBay();
        
                    tcb.SanBayDi = (string)Session["SanBayDi"].ToString();

                if (Session["SanBayDen"] != null)
                {
                    tcb.SanBayDen = (string)Session["SanBayDen"].ToString();
                    
                }
                if ((string)(Session["NgayDi"]) != "")
                {
                    tcb.chuyenbay.NgayDi = Convert.ToDateTime(Session["NgayDi"]);
                    //Session["NgayDi"] = "";
                }
                if((string)Session["NgayVe"]!="")
                {
                    tcb.NgayVe = Convert.ToDateTime(Session["NgayVe"]);
                    //Session["NgayVe"] = "";
                }
                tcb.ThucThi();
                CollectionPager1.MaxPages = 1000;
                CollectionPager1.PageSize = 2;
                CollectionPager1.DataSource = tcb.datatable.DefaultView;
                CollectionPager1.BindToControl = dlChuyenBay;
                dlChuyenBay.DataSource = CollectionPager1.DataSourcePaged;
                dlChuyenBay.DataBind();
                if ((string)Session["LoaiVe"] == "KhuHoi")
                {
                    CollectionPager2.MaxPages = 1000;
                    CollectionPager2.PageSize = 2;
                    CollectionPager2.DataSource = tcb.datatable2.DefaultView;
                    CollectionPager2.BindToControl = dlChuyenBayVe;
                    dlChuyenBayVe.DataSource = CollectionPager2.DataSourcePaged;
                    dlChuyenBayVe.DataBind();
                }
            }
        }
       
        protected void btnThongTinBoSung_Click(object sender, EventArgs e)
        {
            int ChuyenBayDi = 0;
            int ChuyenBayVe = 0;

            foreach (DataListItem item in dlChuyenBay.Items)
            {
                System.Web.UI.HtmlControls.HtmlInputRadioButton rButton = item.FindControl("rdbDatVe") as System.Web.UI.HtmlControls.HtmlInputRadioButton;

               if (rButton.Checked && rButton != null)
                {
                    ChuyenBayDi = Convert.ToInt32(rButton.Value);
                    //Response.Redirect("ThongTinDatVe.aspx?Cbd="+ChuyenBayDi+"");
                }
            }

            foreach (DataListItem item in dlChuyenBayVe.Items)
            {
                HtmlInputRadioButton rButton = item.FindControl("rdbDatVeVe") as HtmlInputRadioButton;

                if (rButton.Checked && rButton != null)
                {
                    ChuyenBayVe = Convert.ToInt32(rButton.Value);
                    //Response.Redirect("ThongTinDatVe.aspx?Cbd="+ChuyenBayDi+"");
                }
            }
            Response.Redirect("ThongTinDatVe.aspx?CBD="+ChuyenBayDi+"&CBV="+ChuyenBayVe);           
        }
       
    }
}